package com.cowain.base.controller.system;

/**
 * @author songxz
 * @date 2022/8/29
 */

import com.cowain.base.core.controller.BaseController;
import com.cowain.base.core.domain.AjaxResult;
import com.cowain.base.core.domain.entity.SysUserEntity;
import com.cowain.base.core.domain.vo.SysUserVo;
import com.cowain.base.core.page.TableDataInfo;
import com.cowain.system.service.SysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户信息
 *
 * @author ruoyi
 */
@Api(tags = "用户管理")
@RestController
@RequestMapping("/system/user")
public class SysUserController extends BaseController {

    @Autowired
    private SysUserService userService;

    /**
     * 获取用户列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysUserEntity user) {
        startPage();

        return null;
    }

    /**
     * 根据用户编号获取详细信息
     */
    @GetMapping(value = {"/", "/{userId}"})
    public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) {

       return null;
    }

    /**
     * 新增用户
     */
    @ApiOperation("新增")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysUserVo user) {
        return toAjax(userService.insertUser(user));
    }

    /**
     * 修改用户
     */
    @ApiOperation("修改")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysUserVo user) {
        userService.updateUser(user);
       return AjaxResult.success();
    }

    /**
     * 删除用户
     */
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds) {
        userService.removeUser(userIds);
        return null;
    }

    /**
     * 重置密码
     */
    @PutMapping("/resetPwd")
    public AjaxResult resetPwd(@RequestBody SysUserVo user) {
        userService.resetPwd(user);
        return null;
    }

    /**
     * 状态修改
     */
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody SysUserEntity user) {
       return null;
    }

    /**
     * 根据用户编号获取授权角色
     */
    @GetMapping("/authRole/{userId}")
    public AjaxResult authRole(@PathVariable("userId") Long userId) {
        AjaxResult ajax = AjaxResult.success();
        return ajax;
    }

    /**
     * 用户授权角色
     */
    @PutMapping("/authRole")
    public AjaxResult insertAuthRole(Long userId, Long[] roleIds) {
        return success();
    }
}